#define _CRT_SECURE_NO_WARNINGS 1

typedef struct {
    int* arr;
    int front;
    int rear;
    int size;
} MyCircularQueue;


MyCircularQueue* myCircularQueueCreate(int k) {
    MyCircularQueue* obj = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
    obj->arr = (int*)malloc(sizeof(int) * (k + 1));
    obj->front = 0;
    obj->rear = 0;
    obj->size = k;
    return obj;
}

bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {
    if ((obj->rear + 1) % (obj->size + 1) == obj->front)
    {
        return false;
    }
    else
    {
        obj->arr[obj->rear] = value;
        obj->rear = (obj->rear + 1) % (obj->size + 1);
        return true;
    }

}

bool myCircularQueueDeQueue(MyCircularQueue* obj) {
    if (obj->front == obj->rear)
    {
        return false;
    }
    else
    {
        obj->front = (obj->front + 1) % (obj->size + 1);
        return true;
    }
}

int myCircularQueueFront(MyCircularQueue* obj) {
    if (obj->front == obj->rear)
    {
        return -1;
    }
    else
    {
        return obj->arr[obj->front];
    }
}

int myCircularQueueRear(MyCircularQueue* obj) {
    if (obj->front == obj->rear)
    {
        return -1;
    }
    else
    {
        return obj->arr[(obj->rear + obj->size) % (obj->size + 1)];
    }
}

bool myCircularQueueIsEmpty(MyCircularQueue* obj) {
    if (obj->front == obj->rear)
    {
        return true;
    }
    else
    {
        return false;
    }
}

bool myCircularQueueIsFull(MyCircularQueue* obj) {
    return (obj->rear + 1) % (obj->size + 1) == obj->front;
    // {
    //     return true;
    // }
    // else
    //     return false;
}

void myCircularQueueFree(MyCircularQueue* obj) {
    free(obj->arr);
    free(obj);
}
